import service from '@/api/request'
import type {
  ChangePasswordReq,
  ChangePasswordRes,
  CheckUser,
  LoginReq,
  LoginRes,
  LogoutRes,
  UpdateUserInfo,
  UpdateUserInfoRes,
  UserInfoRes,
} from './type'

enum API {
  LOGIN_URL = '/auth/login',
  USERINFO_URL = '/auth/profile',
  LOGOUT_URL = '/auth/logout',
  CHANGE_PASSWORD_URL = '/auth/change-password',
  UPDATE_USERINFO_URL = 'users/user/update',
}

export const reqLogin = (data: LoginReq) => {
  return service.post<LoginRes>(API.LOGIN_URL, data)
}

export const reqUserInfo = () => {
  return service.get<UserInfoRes>(API.USERINFO_URL)
}

export const reqLogout = () => {
  return service.post<LogoutRes>(API.LOGOUT_URL)
}

export const reqChangePassword = (data: ChangePasswordReq) => {
  return service.post<ChangePasswordRes>(API.CHANGE_PASSWORD_URL, data)
}

// 修改用户资料
export const reqUpdateUserInfo = (data: UpdateUserInfo) => {
  return service.put<UpdateUserInfoRes>(API.UPDATE_USERINFO_URL, data)
}
